package MultiThread;

import java.util.StringTokenizer;

import GUI.Gui;
import Model.MonteCarloSimulation;

public class Multi3 extends Thread {

	private MonteCarloSimulation simul1;
	private Gui g1;
	private String linetxt1;

	public  Multi3(String name, Gui g, MonteCarloSimulation simul, String linetxt){

		super(name);
		this.g1=g;
		this.simul1=simul;
		this.linetxt1=linetxt;
	}


	public void run(){

		g1.getR().setText("");
		double result;
		StringTokenizer splitline = new StringTokenizer(getLinetxt1(),","); 
		String[] items = new String[splitline.countTokens()] ; 
		int i = 0;
		while ( splitline.hasMoreTokens() )
		{ 
			items[i] = splitline.nextToken(); 
			i++;
		}
		String callputflag=items[0];
		String A=items[1];
		String Z=items[2];
		String E=items[3];
		String R=items[4];
		String T=items[5];
		String Y=items[6];
		String U=items[7];
		String I=items[8];

		double price = Double.parseDouble(A);
		double strike_price = Double.parseDouble(Z);
		double time_year = Double.parseDouble(E);
		double rate = Double.parseDouble(R);
		double rate_holding = Double.parseDouble(T);
		double volatility = Double.parseDouble(Y);
		int nsteps = Integer.parseInt(U);
		int nsimulations = Integer.parseInt(I);

		result=simul1.MonteCarloStandardOption(callputflag,price,strike_price,time_year,rate,rate_holding,volatility,nsteps,nsimulations);
		g1.getR().setText("Result : "+Double.toString(result));
	}

	public String getLinetxt1() {
		return linetxt1;
	}


	public void setLinetxt1(String linetxt1) {
		this.linetxt1 = linetxt1;
	}


	public MonteCarloSimulation getSimul1() {
		return simul1;
	}


	public void setSimul1(MonteCarloSimulation simul1) {
		this.simul1 = simul1;
	}


	public Gui getG1() {
		return g1;
	}


	public void setG1(Gui g1) {
		this.g1 = g1;
	}
}

